<?php


namespace App\Rpc\common\impl;


use App\Rpc\common\UploadInterface;
use App\Service\common\uploadService;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Hyperf\Config\Annotation\Value;

/**
 * 文件上传
 */
class UploadImpl implements UploadInterface
{
    /**
     * @Value("commonset.pathType")
     */
    protected $pathType;

    /**
     * 文件上传
     * @param array $params
     * @return array
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function uploadAvatar(object $avatar, array $params): array
    {
        // ApplicationContext::getContainer()->get(UploadRequest::class)->validated($params, __FUNCTION__);
        if ($this->pathType == 1) {
            return make(uploadService::class)->uploadAvatar($avatar, $params);
        } else {
            return make(uploadService::class)->uploadAvatarOss($avatar, $params);
        }
    }

    /**
     * 聊天文件上传
     * @param array $params
     * @return array
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function uploadChatFile(object $file, array $params): array
    {
        // ApplicationContext::getContainer()->get(UploadRequest::class)->validated($params, __FUNCTION__);
        if ($this->pathType == 1) {
            return make(uploadService::class)->uploadChatFile($file, $params);
        } else {
            return make(uploadService::class)->uploadChatFileOss($file, $params);
        }
    }


}